#ifndef _MMPF_USBUVC_H264_H
#define _MMPF_USBUVC_H264_H
#include "config_fw.h"
#include "mmpf_typedef.h"
#if SKYPE_UVC_H264

#define DUAL_AUX_STREAM_EN    (1<<0)
#define DUAL_AUX_H264         (1<<1)
#define DUAL_AUX_YUY2         (1<<2)
#define DUAL_AUX_NV12         (1<<3)
#define AUX_MJPEG_PAYLOAD     (1<<6)


// 3.3 H.264 UVC Extension Unit definition
#define UVCX_VIDEO_CONFIG_PROBE     (0x01)
#define UVCX_VIDEO_CONFIG_COMMIT    (0x02)
#define UVCX_CONTROL_MODE           (0x03)
#define UVCX_TEMPORAL_SCALE_MODE    (0x04)
#define UVCX_SPATIAL_SCALE_MODE     (0x05)
#define UVCX_SNR_SCALE_MODE         (0x06)
#define UVCX_RESERVED_7             (0x07)
#define UVCX_RESERVED_8             (0x08)
#define UVCX_PICTURE_TYPE_CONTROL   (0x09)
#define UVCX_VERSION                (0x0a)
#define UVCX_ENCODER_RESET          (0x0b)
#define UVCX_FRAMERATE_CONFIG       (0x0c)
#define UVCX_VIDEO_ADVANCE_CONFIG   (0x0d)
#define UVCX_BITRATE_LAYERS         (0x0e)
#define UVCX_QP_STEPS_LAYERS        (0x0f)

#define bMaxLayers      1

typedef enum {
    SINGLE_SLICE  =0,
    MULTI_SLICE_BITs,
    MULTI_SLICE_MBs ,
    MULTI_SLICE_NUMs
} H264SliceMode ;

typedef enum {
    CONSTRAINED_BASELINE_P = 0x4240,
    BASELINE_P = 0x4200 ,
    MAIN_P = 0x4D00,
    HIGH_P = 0x6400,
    SCALABLE_BASELINE_P=0x5300,
    SCALABALE_HIGH_P = 0x5600,
    MULTIVIEW_HIGH_P = 0x7600,
    STEREO_HIGH_P = 0x8000,
    CONSTRAINED_SET1_FLAG = 0x0040,
    CONSTRAINED_SET2_FLAG = 0x0020,
    CONSTRAINED_SET3_FLAG = 0x0010,
    CONSTRAINED_SET4_FLAG = 0x0008,
    CONSTRAINED_SET5_FLAG = 0x0004
   
} H264Profile ;

typedef enum {
    
    REALTIME_H264  = 1 ,
    BROADCAST_H264     ,
    STORAGE_H264       ,
    UCCONFIG_MODE1     ,
    UCCONFIG_MODE2     ,
    UCCONFIG_MODE3     ,
    UCCONFIG_MODE4     
} H264UsageType ;


typedef enum {
    RESERVED_H264=0,
    CBR_H264 = 1 ,
    VBR_H264 = 2 ,
    CONSTANT_H264_QP = 3,
    NUM_H264_CTLMODE,
    FIXED_FRAME_RATE = 0x10    
} H264RateControlMode ;

typedef enum {
    ONE_LAYER_H264 = 1,
    TWO_LAYER_H264 ,
    THREE_LAYER_H264 ,
    FOUR_LAYER_H264, 
    FIVE_LAYER_H264,
    SIX_LAYER_H264,
    SEVEN_LAYER_H264
} H264TemporalScaleMode ;

typedef enum {
    ONE_SPATIAL_LAYER = 1,
    TWO_SPATIAL_LAYER ,
    THREE_SPATIAL_LAYER ,
    FOUR_SPATIAL_LAYER ,
    FIVE_SPATIAL_LAYER ,
    SIX_SPATIAL_LAYER ,
    SEVEN_SPATIAL_LAYER ,
    EIGHT_SPATIAL_LAYER
} H264SpatialScaleMode ;

typedef enum {
    ONE_QUALITY_LAYER = 1 ,
    GS_NONREWRITE_2LAYER,
    GS_NONREWRITE_3LAYER,
    CGS_REWRITE_2LAYER,
    CGS_REWRITE_3LAYER,
    MGS_2LAYER ,
    ALLMOMODES 
    
} H264SNRScaleMode ;

typedef enum {
    ANNEXB_H264 = 0,
    NAL_H264
} H264SliceFormat ;

typedef enum {
    CAVLC_H264 =0,
    CABAC_H264 
} H264EntroyCABAC ;

typedef enum {
    PIC_I_FRAME = 0,
    PIC_IDR_FRAME ,
    PIC_IDR_WITH_NEW_SPSPPS,
    PIC_IDR_LONGTERM,
    PIC_IDR_LONGTERM_WITH_SPSPPS,
    PIC_P_LONGTERM
} H264PicType ;


#define     UVCX_VIDEO_CONFIG_PROBE_LEN                  (46)           
#define     UVCX_VIDEO_CONFIG_COMMIT_LEN                 (46) 
#define     UVCX_CONTROL_MODE_LEN                        (3)           
#define     UVCX_TEMPORAL_SCALE_MODE_LEN                 (3)           
#define     UVCX_SPATIAL_SCALE_MODE_LEN                  (3)           
#define     UVCX_SNR_SCALE_MODE_LEN                      (4)           
#define     UVCX_VERSION_LEN                             (2)           

// 3.3.3 V1.0
typedef __packed struct _UVCX_RateControlMode {
	MMP_USHORT	wLayerID;
	MMP_UBYTE	bRateControlMode;
} UVCX_RateControlMode ;
#define UVCX_RATECONTROLMODE_LEN    sizeof(UVCX_RateControlMode)

// 3,3.9 UVCX_PICTURE_TYPE_CONTROL
typedef __packed struct _UVCX_PictureTypeCtl {
    MMP_USHORT wLayerID ; // Long -> short 
    MMP_USHORT wPicType ;
} UVCX_PictureTypeCtl ;

#define UVCX_PIC_TYPE_LEN  (sizeof(UVCX_PictureTypeCtl))

// 3,3.12 UVCX_FRAMERATE_CONFIG
typedef __packed struct _UVCX_FrameRateConfig {
    MMP_USHORT wLayerID ; // Long -> short 
    MMP_ULONG dwFrameInterval ;
} UVCX_FrameRateConfig ;

#define UVCX_FRAMERATE_LEN  (sizeof(UVCX_FrameRateConfig))

// 3.3.13 UVCX_VIDEO_ADVANCE_CONFIG
typedef __packed struct _UVCX_AdvConfig {
    MMP_USHORT wLayerID ; // Long -> short 
    MMP_ULONG dwMb_max;
    MMP_UBYTE bLevel_idc;
    MMP_UBYTE bReserved ;
} UVCX_AdvConfig ;

#define UVCX_ADVCONFIG_LEN  (sizeof(UVCX_AdvConfig))

// 3,3.14 UVCX_BITRATE_LAYERS
typedef __packed struct _UVCX_BitRateLayers {
    MMP_USHORT wLayerID ; // Long -> short 
    MMP_ULONG dwPeakBitrate ;
    MMP_ULONG dwAverageBitrate;
} UVCX_BitRateLayers ;

#define UVCX_BITRATE_LEN    (sizeof(UVCX_BitRateLayers))

typedef __packed struct _UVCX_QPVal
{
    MMP_UBYTE bMinQp,bMaxQp ;
} UVCX_QPVal ;

// 3,3.15 UVCX_QP_STEPS_LAYERS
typedef __packed struct _UVCX_QPStepSize
{
    MMP_USHORT wLayerID ;
    MMP_UBYTE bFrameType;
    MMP_BYTE bMinQp;
    MMP_BYTE bMaxQp;
} UVCX_QPStepSize ;

#define UVCX_QPSTEP_SIZE_LEN (sizeof(UVCX_QPStepSize)) 


typedef __packed struct _UVCX_CropConfig
{
    MMP_USHORT wCropLeftOffset ;
    MMP_USHORT wCropRightOffset ;
    MMP_USHORT wCropTopOffset ;
    MMP_USHORT wCropBottomOffset ;
    
} UVCX_CropConfig;
#define UVCX_CROP_CONFIG_LEN sizeof(UVCX_CropConfig)


// 3.3.2 UVCX_VIDEO_CONFIG_PROBE & UVCX_VIDEO_CONFIG_COMMIT
// Appendix-B H264 Video Config
typedef __packed struct _UVCX_VIDEO_CONFIG {
    MMP_ULONG dwFrameInterval;
    MMP_ULONG dwBitRate;
    MMP_USHORT bmHints;
    MMP_USHORT wConfigurationIndex;
    MMP_USHORT wWidth;
    MMP_USHORT wHeight;
    MMP_USHORT wSliceUnits;
    MMP_USHORT wSliceMode;
    MMP_USHORT wProfile;
    MMP_USHORT wIFramePeriod;
    MMP_USHORT wEstimatedVideoDelay;
    MMP_USHORT wEstimatedMaxConfigDelay;
    MMP_UBYTE bUsageType;
    MMP_UBYTE bRateControlMode;
    MMP_UBYTE bTemporoalScaleMode;
    MMP_UBYTE bSpatialScaleMode;
    MMP_UBYTE bSNRScaleMode;
    MMP_UBYTE bStreamMuxOption;
    MMP_UBYTE bSliceFormat;
    MMP_UBYTE bEntropyCABAC;
    MMP_UBYTE bTimestamp;
    MMP_UBYTE bNumOfReorderFrames;
    MMP_UBYTE bPreviewFlipped;
    MMP_UBYTE bView;
    MMP_UBYTE bReserved1;
    MMP_UBYTE bReserved2;
    MMP_UBYTE bStreamID ;
    MMP_UBYTE bSpatialLayerRatio;
    MMP_USHORT wLeakyBucketSize;
} UVCX_VIDEO_CONFIG;

void UVCX_SetCurVideoProbeConfig(UVCX_VIDEO_CONFIG *config_commit);
UVCX_VIDEO_CONFIG *UVCX_GetCurVideoProbeConfig(void);
void UVCX_CommitH264Config(UVCX_VIDEO_CONFIG *config_commit);
UVCX_VIDEO_CONFIG *UVCX_GetH264StartConfig(void);
void UVCX_CommitPreviewConfig(UVCX_VIDEO_CONFIG *config_commit);
UVCX_VIDEO_CONFIG *UVCX_GetPreviewStartConfig(void);
MMP_USHORT UVCX_SetH264StartMode(UVCX_VIDEO_CONFIG *config);
MMP_USHORT UVCX_SetH264ControlMode(UVCX_RateControlMode *ctlMode) ;
MMP_USHORT UVCX_SetH264TemporalScaleMode(H264TemporalScaleMode tempScaleMode);
MMP_USHORT UVCX_SetH264SpatialScaleMode(H264SpatialScaleMode spatialScaleMode);
MMP_USHORT UVCX_SetH264SNRScaleMode(H264SNRScaleMode spatialScaleMode);
MMP_USHORT UVCX_SetH264BitRate(MMP_UBYTE ubEncId, UVCX_BitRateLayers *bRc);
MMP_USHORT UVCX_SetH264QPStepSize(UVCX_QPStepSize *qStep);
MMP_USHORT UVCX_SetH264PictureTypeCtl(H264PicType picType);
//MMP_USHORT UVCX_SetH264CropConfig(UVCX_CropConfig *crop);
MMP_USHORT UVCX_SetH264FrameRate(MMP_UBYTE ubEncId, MMP_ULONG frameRate);
//MMP_USHORT UVCX_SetH264AdvConfig(UVCX_AdvConfig *advConfig);
//MMP_USHORT UVCX_SetH264FlipMode(MMP_USHORT flip_id);
void UVCX_EnableSliceBasedTx(MMP_BOOL en);
MMP_BOOL UVCX_IsSliceBasedTx(void);
MMP_USHORT UVCX_SetH264GOPCount(MMP_UBYTE ubEncId, MMP_ULONG GOPCnt);
#endif

#endif



